package com.me.study.designPatterns.Singleton;

import java.util.concurrent.CyclicBarrier;

/**
 * 枚举实现单例模式
 * @Author ME
 * @Date 2020/7/6 18:34
 */
public enum EnumSingleton {
    /** 枚举实现的单例对象 */
    INSTANCE;

    EnumSingleton() {
        System.out.println("实例化了。。。");
    }

    public static void main(String[] args) {
        int count = 1000;
        CyclicBarrier barrier = new CyclicBarrier(count);
        for (int i = 0; i < count; i++) {
            new Thread(() -> {
                try {
                    barrier.await();
                    EnumSingleton instance = EnumSingleton.INSTANCE;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, Integer.toString(i)).start();
        }
    }
}
